package com.cineplanet.dew.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.cineplanet.dew.exception.DAOExcepcion;
import com.cineplanet.dew.modelo.Cine;
import com.cineplanet.dew.modelo.Merchandizing;
import com.cineplanet.dew.modelo.Pelicula;
import com.cineplanet.dew.service.CineService;
import com.cineplanet.dew.service.MerchandizingService;
import com.cineplanet.dew.service.PeliculaService;

public class DetallePeliculaController extends MultiActionController{
	
	private PeliculaService peliculaService;
	
	public PeliculaService getPeliculaService() {
		return peliculaService;
	}

	public void setPeliculaService(PeliculaService peliculaService) {
		this.peliculaService = peliculaService;
	}

	private CineService cineService;
	
	public CineService getCineService() {
		return cineService;
	}

	public void setCineService(CineService cineService) {
		this.cineService = cineService;
	}
	
	private MerchandizingService merchandizingService;
	
	public MerchandizingService getMerchandizingService() {
		return merchandizingService;
	}

	public void setMerchandizingService(MerchandizingService merchandizingService) {
		this.merchandizingService = merchandizingService;
	}

	public ModelAndView index(HttpServletRequest request,HttpServletResponse response)  {
		int idPelicula = Integer.parseInt(request.getParameter("idPelicula"));
		String subTitulada = "Si";

		try {
			Pelicula pelicula = peliculaService.obtenerDetalleCualquierPelicula(idPelicula);
			List<Merchandizing> merchandizing = merchandizingService.obtenerMerchandizing(idPelicula);
			List<Cine> cines = cineService.cinesPorPela(idPelicula);
			
			
			if(pelicula.getSubtitulada() == (byte)0)
				subTitulada = "No";
		
			request.setAttribute("cines", cines);
			request.setAttribute("mercha", merchandizing);
			request.setAttribute("subtitulada", subTitulada);
			request.setAttribute("pelicula", pelicula);
		} catch (DAOExcepcion e) {
			e.printStackTrace();
		}
		
		return new ModelAndView("details");
    }
}
